package com.lc.midi.mid;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Midi {
	
	private MidiHead midiHead = new MidiHead();
	private List<MidiTrack> midiTracks = new ArrayList<MidiTrack>();
	
//	public void check(byte[] data) throws IOException, MidiException {
//		entity.Midi midi = new entity.Midi();
//		midi.setData(data);
//		MidiFile midiFile = new MidiFile(midi);
//		read(midiFile);
//	}
	
	public int read(MidiFile midiFile) throws IOException, MidiException {
		int returnLen = 0;
		returnLen += midiHead.read(midiFile);
		int trackNum = midiHead.getMtrkNum();
		for (int i = 0; i < trackNum; i++) {
			MidiTrack midiTrack = new MidiTrack();
			returnLen += midiTrack.read(midiFile);
			midiTracks.add(midiTrack);
		}
		midiFile.getMidiStream().close();
		return returnLen;
	}
	
	public Midi() {}
	
	public Midi(MidiFile midiFile) throws IOException, MidiException {
		read(midiFile);
	}
	
	public MidiHead getHead() {
		return midiHead;
	}
	public List<MidiTrack> getTracks(){
		return midiTracks;
	}
}
